#!/bin/bash

VERSION=`date '+%Y%m%d'`
ARCH=i486
PKG=odhal
PARAMS='--owner 1000 --group 1000 --same-permissions --exclude "*~" --exclude .svn'

make || exit 1

rm -fr pkg/odhal*.tar.gz
chmod ug+x etc/init.d/odhal
chmod o-rwx etc/init.d/odhal
chmod 0770 usr/local/opendomo/services/config/*.sh

#rm -fr usr/share/ -fr 2>/dev/null
#mkdir -p usr/share/templates/arduino
#cp arduino/templates/* usr/share/templates/arduino/

strip usr/bin/*


echo "Micropik driver" > pkg/odhal_micropik.desc
tar cfz pkg/odhal_micropik-$VERSION.od.$ARCH.tar.gz usr/bin/micropik $PARAMS

echo "Arduino driver" > pkg/odhal_arduino.desc
tar cfz pkg/odhal_arduino-$VERSION.od.$ARCH.tar.gz usr/bin/arduino $PARAMS 

echo "X10 CM15a driver" > pkg/odhal_x10.desc
tar cfz pkg/odhal_x10-$VERSION.od.$ARCH.tar.gz var usr/bin/x10 $PARAMS 

echo "ODControl driver" > pkg/odhal_domino.desc
tar cfz pkg/odhal_domino-$VERSION.od.$ARCH.tar.gz var usr/bin/domino etc/opendomo/control $PARAMS 


cp pkg/*.desc ./var/pkg
tar vcfz pkg/$PKG-$VERSION.od.$ARCH.tar.gz usr/local usr/share usr/bin/dummy etc/opendomo/eventhandlers etc/opendomo/root etc/init.d var $PARAMS 

